const api = require("../../../utils/api")
const getwxphone = require("../../../utils/getwxphone")
Page({

  /**
   * 页面的初始数据
   */
  data: {
    page_index: "zwjs",
    show_tab_bar: !0,
    nianfenList: ['2021', '2022','2023'],
    eduList: ['师范类专科及以上', '专科及以上', '本科及以上', '硕士研究生及以上'],
    gangweiList: ['支农', '支教', '支医', '林草', '帮扶乡村振兴', '就业和社会保障服务平台', ' 其他', ' 水利'],
    mainshow: 1,
  },

  getPhoneNumber(e) {
    var _ = this;
    console.log(e)
    const info = {
      area: wx.getStorageSync('area'),
      agent: wx.getStorageSync('agent'),
      page: wx.getStorageSync('page'),
      activeId: 32
    }

    getwxphone(e.detail.code, 52769, 'chaxun', info)
      .then(res => {
        console.log(res);
        _.setData({
          login: !1
        })
      })
      .catch(err => {
        console.log(err);
      })
  },
  xz: function (e) {
    var _ = this;
    var flag = e.detail.value[0];
    if (flag == undefined) {
      flag = false
    } else {
      flag = true
    }
    _.setData({
      flag
    })
    console.log(_.data.flag)
  },
  xy: function (e) {
    var _ = this;
    wx.navigateTo({
      url: '../agreement/agreement',
    })
  },
  clear() {
    var _ = this;
    _.setData({
      nianfen: '',
      city: '',
      edu: '',
      gangwei: '',
    })
  },
  //个人信息查询提交
  submit() {
    var _ = this;
    var phone = wx.getStorageSync('52769phone')
    var edu = _.data.edu;
    
    if (phone) {

      if (_.data.city && _.data.edu && _.data.gangwei && _.data.nianfen) {
        if(_.data.city == _.data.province){
          _.data.city = ''
        }
        wx.request({ //发送请求
          url: 'https://zg99.offcn.com/index/chaxun/getlist?actid=52769&callback=?', //接收url
          data: {
            limits: 200,
            nianfen: _.data.nianfen,
            city: _.data.city,
            dishi: _.data.province,
            edu: _.data.edu,
            gangwei: _.data.gangwei,
            sstimes:new Date()
          }, //接收参数
          success(res) {
            console.log('2') //返回
            var jsonStr = res.data;
            jsonStr = jsonStr.replace("(", "");
            jsonStr = jsonStr.replace(")", "");
            if (typeof jsonStr != 'object') {
              jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
              var theJson = JSON.parse(jsonStr);
            }
            console.log(theJson)
            var list = [];
            for (var i in theJson.lists) { //循环写入下来框
              list.push(theJson.lists[i])
            }
            _.setData({
              selfres: list
            });
            if (list.length != 0) {
              wx.setStorageSync('theJson', list)
              wx.navigateTo({
                url: "../zwjs_result/zwjs_result"
              });
              console.log(list)
            } else {
              wx.showToast({
                title: '无符合条件岗位',
              })
            }

          }
        })
      } else {
        wx.showToast({
          title: '请完整填写信息',
          duration: 2000,
          icon: 'none'
        })
      }
    } else {
      _.setData({
        login: 1
      })
    }


  },

  gozx: function () {
    wx.navigateTo({
      url: '../../xiaoneng/xiaoneng',
    })
  },
  godjk1:function(){
    wx.navigateToMiniProgram({
      appId: 'wx6b75078563b749b0',
      path: 'pages/yitiyima/yitiyima?scene=2ecee443cc7d49508d61a6bba24ae754&mis=ch29220',
      envVersion: 'release',
      success(res) {
        // 打开成功
      }
    })
  },
  godjk2:function(){
    wx.navigateToMiniProgram({
      appId: 'wx6b75078563b749b0',
      path: 'pages/yitiyima/yitiyima?scene=9b6bc3bae3324472b5902bd5be550ea5&mis=ghn62534',
      envVersion: 'release',
      success(res) {
        // 打开成功
      }
    })
  },
  godjk3:function(){
    wx.navigateToMiniProgram({
      appId: 'wx6b75078563b749b0',
      path: 'pages/yitiyima/yitiyima?scene=faed52562f7849f39ee41d1a13400725&mis=ghn62534',
      envVersion: 'release',
      success(res) {
        // 打开成功
      }
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    api.load(options)
    this.province();
  },


  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },
  mainshow() {
    var _ = this;
    _.setData({
      mainshow: !1,
    })
  },
  closeselect() {
    var _ = this;
    _.setData({
      bindpro: !1,
      bindmajor: !1,
      bindedu: !1,
      bindgangwei: !1,
      bindnianfen: !1,
    })
  },
  //点击选择-年份nianfen
  choisenianfen() {
    var _ = this;
    _.setData({
      bindnianfen: 1,
    })
  },
  //点击选择-年份nianfen
  setnianfen(e) {
    var _ = this;
    console.log(e.currentTarget.dataset.nianfen)
    _.setData({
      nianfen: e.currentTarget.dataset.nianfen,
      bindnianfen: !1
    })
  },
  //点击选择-学历edu
  choiseMajor() {
    var _ = this;
    if (_.data.edu) {
      _.setData({
        bindmajor: 1,
      })
      _.xuekemenlei()
    } else {
      wx.showToast({
        title: '请先选择学历',
        icon: 'none'
      })
    }

  },
  //点击选择-学历edu
  choiseEdu() {
    var _ = this;
    _.setData({
      bindedu: 1,
    })
  },
  //点击选择-学历edu
  setedu(e) {
    var _ = this;
    console.log(e.currentTarget.dataset.edu)

    _.setData({
      edu: e.currentTarget.dataset.edu,
      bindedu: !1
    })
  },
  //点击选择-岗位类别gangwei
  choisegangwei() {
    var _ = this;
    _.setData({
      bindgangwei: 1,
    })
  },
  //点击选择-岗位类别gangwei
  setgangwei(e) {
    var _ = this;
    console.log(e.currentTarget.dataset.gangwei)
    _.setData({
      gangwei: e.currentTarget.dataset.gangwei,
      bindgangwei: !1
    })
  },
  //点击选择-省份地市
  choiseProvince() {
    var _ = this;
    _.setData({
      bindpro: 1,
    })
  },
  //一级联动-省份
  province() {
    var _ = this;
    wx.request({ //发送请求
      url: 'https://zg99.offcn.com/index/chaxun/getlevel?actid=43761&callback=?', //接收url
      data: {
        level: '1',
        province: ''
      }, //接收参数
      success(res) { //返回
        var jsonStr = res.data;
        jsonStr = jsonStr.replace("(", "");
        jsonStr = jsonStr.replace(")", "");
        if (typeof jsonStr != 'object') {
          jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
          var theJson = JSON.parse(jsonStr);
        }
        console.log(theJson)
        var list = [];
        for (var i in theJson.lists) { //循环写入下来框
          list.push(theJson.lists[i].province)
        }
        // console.log(list)
        _.setData({
          provinceList: list
        });
      }
    })
  },
  //点击选择-省份
  setProvince(e) {
    var _ = this;
    console.log(e.currentTarget.dataset.province)
    _.setData({
      province: e.currentTarget.dataset.province
    })
    _.city()
  },
  //点击重新选择-省份
  rechoiseprovince() {
    var _ = this;
    _.setData({
      cityList: !1,
      city: !1
    })
  },
  //二级联动-地市
  city() {
    var _ = this;
    wx.request({ //发送请求
      url: 'https://zg99.offcn.com/index/chaxun/getlevel?actid=43761&callback=?', //接收url
      data: {
        level: '2',
        grfiled: 'province',
        grtext: _.data.province
      }, //接收参数
      success(res) { //返回
        var jsonStr = res.data;
        jsonStr = jsonStr.replace("(", "");
        jsonStr = jsonStr.replace(")", "");
        if (typeof jsonStr != 'object') {
          jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
          var theJson = JSON.parse(jsonStr);
        }
        // console.log(theJson)
        var list = [];
        for (var i in theJson.lists) { //循环写入下来框
          list.push(theJson.lists[i].city)
        }
        console.log(list)
        _.setData({
          cityList: list
        });
      }
    })
  },
  //点击选择-地市
  setCity(e) {
    var _ = this;
    console.log(e.currentTarget.dataset.city)
    if (e.currentTarget.dataset.city == '不限') {
      var city = _.data.province
    } else {
      var city = e.currentTarget.dataset.city
    }
    console.log(city)
    _.setData({
      city: city,
      cityList: !1,
      bindpro: !1
    })
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    var _ = this;
    var area = wx.getStorageSync('area')
    var agent = wx.getStorageSync('agent')
    var page = wx.getStorageSync('page')
    return {
      title: '2023山东三支一扶职位查询',
      path: 'pages/zwjs/zwjs/zwjs?area=' + area + '&agent=' + agent + '&page=' + page
    }

  },
  /**分享到朋友圈*/
  onShareTimeline: function () {
    var _ = this;
    var area = wx.getStorageSync('area')
    var agent = wx.getStorageSync('agent')
    var page = wx.getStorageSync('page')
    return {
      title: '2023山东三支一扶职位查询',
      path: 'pages/zwjs/zwjs/zwjs?area=' + area + '&agent=' + agent + '&page=' + page
    }
  }

})